package com.zzw.redis;

import com.google.gson.Gson;
import com.zzw.service.UserService;
import com.zzw.until.FastJsonUntil;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.data.redis.core.RedisTemplate;

import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

public class SyncListener implements MessageListener {

    @Autowired
    private RedisTemplate<Serializable, Serializable> redisTemplate;

    private static Logger logger = Logger.getLogger(SyncListener.class);

    public void onMessage(Message message, byte[] bytes) {
        byte[] body = message.getBody();
        byte[] channel = message.getChannel();
        String msgContent = (String) redisTemplate.getValueSerializer().deserialize(body);
        List list = FastJsonUntil.jsonToList(msgContent);
        System.out.println(list.get(0));
        String topic = (String) redisTemplate.getStringSerializer().deserialize(channel);
        System.out.println("topic:" + topic + ":" + msgContent);
    }
}
